#!/bin/bash
# This file is part of the jetson_stats package (https://github.com/rbonghi/jetson_stats or http://rnext.it).
# Copyright (c) 2019 Raffaello Bonghi.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Emulator for NVIDIA Jetson jetson_clock

usage()
{
	if [ "$1" != "" ]; then
    	tput setaf 1
		echo "$1"
		tput sgr0
	fi
	
    echo "jetson_clock, EMULATOR of NVIDIA Jetsons"
    echo "Maximize jetson performance by setting static max frequency to CPU, GPU and EMC clocks."
    echo "Usage:"
    echo "$0 [options]"
    echo "options,"
    echo "   -h|--help        | This help"
    echo "   --show           | display current settings"
    echo "   --restore [file] | restore current settings to a file (default: ${HOME}/l4t_dfs.conf)"
    echo "   --store [file]   | store current settings to a file (default: ${HOME}/l4t_dfs.conf)"
    echo "run jetson_clocks.sh without any option to set static max frequency to CPU, GPU and EMC clocks."
}

show()
{
    echo "Show status jetson_clock"
}

main()
{
    local TIME_SLEEP=1
    local conf=""
	# Decode all information from startup
    while [ -n "$1" ]; do
        case "$1" in
            --show)
                show
                exit 0
                ;;
            --restore)
                conf=$2
                shift 1
                exit 0
                ;;
            --store)
                conf=$2
                shift 1
                exit 0
                ;;
            -h|--help)
                usage
                exit 0
                ;;
            *)
                usage "[ERROR] Unknown option: $1"
                exit 1
            ;;
        esac
            shift 1
    done
    
    if [ "$EUID" -ne 0 ] ; then
      echo "Please run as root"
      exit 1
    fi
    
    # Go to sleep for an interval
    sleep $TIME_SLEEP
}

main $@
exit 0

# EOF
